package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.product.RCNormalizerService;
import com.shrct.businessprocess.product.RCProductEntry;
import com.shrct.businessprocess.product.RCProductEntryCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;
import org.springframework.beans.factory.BeanFactory;

public class RCProductEntryCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProductEntry> implements RCProductEntryCriteria {
  private RCEnterprise enterprise;
  
  public RCEnterprise getEnterprise() {
    return this.enterprise;
  }
  
  public RCProductEntryCriteria setEnterprise(final RCEnterprise enterprise) {
    this.enterprise = enterprise;
    return this;			
    
  }
  
  private String projectId;
  
  public String getProjectId() {
    return this.projectId;
  }
  
  public RCProductEntryCriteria setProjectId(final String projectId) {
    this.projectId = projectId;
    return this;			
    
  }
  
  private String sid;
  
  public String getSid() {
    return this.sid;
  }
  
  public RCProductEntryCriteria setSid(final String sid) {
    this.sid = sid;
    return this;			
    
  }
  
  private String productSpec;
  
  public String getProductSpec() {
    return this.productSpec;
  }
  
  public RCProductEntryCriteria setProductSpec(final String productSpec) {
    this.productSpec = productSpec;
    return this;			
    
  }
  
  public void postInitialize() {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCNormalizerService _bean = _beanFactory.<RCNormalizerService>getBean(RCNormalizerService.class);
    String _normalizeSid = _bean.normalizeSid(this.sid);
    this.sid = _normalizeSid;
    BeanFactory _beanFactory_1 = this.getBeanFactory();
    RCNormalizerService _bean_1 = _beanFactory_1.<RCNormalizerService>getBean(RCNormalizerService.class);
    String _normalizeSid_1 = _bean_1.normalizeSid(this.productSpec);
    this.productSpec = _normalizeSid_1;
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.product.impl.RCProductEntryImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSid()) ){
    	hql += " and (this.normalizedSid  LIKE :sid)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductSpec()) ){
    	hql += " and (this.type.code  LIKE :productSpec)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEnterprise()) ){
    	hql += " and ((this.enterprise) = (:enterprise))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectId()) ){
    	hql += " and (this.projectId  LIKE :projectId)" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductSpec()) ){
    	hql += " and (this.type.normalizedCode  LIKE :productSpec)" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEnterprise())){
    	query.setParameter("enterprise",getEnterprise()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectId())){
    	query.setParameter("projectId",getProjectId()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSid())){
    	query.setParameter("sid",getSid()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductSpec())){
    	query.setParameter("productSpec",getProductSpec()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCProductEntryCriteriaImpl() {
    initOrderBys();
  }
}
